package com.tbit.api;

import com.tbit.manager.api.AgentDepositVipApi;
import com.tbit.manager.api.dto.AgentDepositVipDTO;
import com.tbit.uqbike.object.pojo.AgentDepositVip;
import com.tbit.uqbike.object.pojo.UserMember;
import com.tbit.uqbike.object.pojo.VipCard;
import com.tbit.uqbike.service.business.AgentDepositVipService;
import com.tbit.uqbike.service.business.VipCardService;
import com.tbit.uqbike.webmanager.util.LogUtil;
import com.tbit.utils.DateTimeUtil;
import com.tbit.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * 用户区域免押实现
 *
 * @since 2024/11/28
 */
@RestController
@Slf4j
public class AgentDepositVipApiImpl implements AgentDepositVipApi {

    @Autowired
    private AgentDepositVipService agentDepositVipService;
    @Autowired
    private VipCardService vipCardService;

    @Override
    public void editAgentDepositVip(AgentDepositVipDTO agentDepositVipDTO) {
        String date = DateTimeUtil.format(agentDepositVipDTO.getExpireTime(), DateUtil.YMD_);
        agentDepositVipDTO.setExpireDt(date);
        AgentDepositVip agentDepositVip = new AgentDepositVip();
        BeanUtils.copyProperties(agentDepositVipDTO, agentDepositVip);
        agentDepositVipService.edit(agentDepositVip);
        LogUtil.info(agentDepositVipDTO.getLoginUserAccountUserId() + "修改用户免押卡,用户id=" + agentDepositVip.getUserId());
    }

    @Override
    public AgentDepositVipDTO getByUserIdAndAccountId(Integer userId, Integer accountId) {
        AgentDepositVip agentDepositVip = agentDepositVipService.getByUserId(userId, accountId);
        AgentDepositVipDTO agentDepositVipDTO = new AgentDepositVipDTO();
        BeanUtils.copyProperties(agentDepositVip, agentDepositVipDTO);
        return agentDepositVipDTO;
    }
}
